 $ontext
[1]        $model:sj
[2]        
[3]        $sectors:
[4]          xcom(sect)        ! production
[5]          w                 ! welfare
[6]        
[7]        $commodities:
[8]          pc(sect)          ! price of commodity sect
[9]          pf(fac)           ! price of factor fac
[10]         pw                ! consumer price index
[11]       
[12]       $consumers:
[13]         y                 ! total nominal household expenditure
[14]       
[15]       $prod:xcom(sect)    s:1.0
[16]         o:pc(sect)        q:qcom(sect)
[17]         i:pc(good)        q:qcomin(good,sect)
[18]         i:pf(fac)         q:qfacin(fac,sect)
[19]       
[20]       $prod:w             s:1.0
[21]         o:pw              q:qw
[22]         i:pc(good)        q:qhous(good)
[23]       
[24]       $demand:y
[25]         d:pw
[26]         e:pf(fac)         q:endow(fac)
 $offtext

*   Alert the user to undefined sets or parameters which are referenced in the MPSGE model:

$if not settype sect       $abort "sect should be a SET."
$if not settype fac        $abort "fac should be a SET."
$if not settype good       $abort "good should be a SET."
$if not partype qcom       $abort "qcom should be a PARAMETER."
$if not dimension 1 qcom   $abort "qcom has an inconsistent dimension."
$if not partype qcomin     $abort "qcomin should be a PARAMETER."
$if not dimension 2 qcomin $abort "qcomin has an inconsistent dimension."
$if not partype qfacin     $abort "qfacin should be a PARAMETER."
$if not dimension 2 qfacin $abort "qfacin has an inconsistent dimension."
$if not partype qw         $abort "qw should be a PARAMETER."
$if not dimension 0 qw     $abort "qw has an inconsistent dimension."
$if not partype qhous      $abort "qhous should be a PARAMETER."
$if not dimension 1 qhous  $abort "qhous has an inconsistent dimension."
$if not partype endow      $abort "endow should be a PARAMETER."
$if not dimension 1 endow  $abort "endow has an inconsistent dimension."

*    Define aliases for sets:

alias (sect,sect_); 
alias (fac,fac_);   
alias (good,good_); 

*    Benchmark costs and value shares:

PARAMETER

*    Benchmark costs:

        c0_002(sect,good) Benchmark cost for input pc(good) in sector xcom(sect)
        c0_003(sect,fac)  Benchmark cost for input pf(fac) in sector xcom(sect)
        c0_001(sect)      Benchmark cost for input nest s in sector xcom(sect)
        c0_007(good)      Benchmark cost for input pc(good) in sector w
        c0_006            Benchmark cost for input nest s in sector w

*    Benchmark revenue:

        r0_005(sect) Benchmark revenue for output pc(sect) in sector xcom(sect)
        r0_004(sect) Benchmark revenue for output nest t in sector xcom(sect)
        r0_009       Benchmark revenue for output pw in sector w
        r0_008       Benchmark revenue for output nest t in sector w

*    Benchmark shares:

        theta_002(sect,good) Benchmark share for input  pc(good) in nest s for sector xcom(sect)
        theta_003(sect,fac)  Benchmark share for input  pf(fac) in nest s for sector xcom(sect)
        theta_005(sect)      Benchmark share for output pc(sect) in nest t for sector xcom(sect)
        theta_007(good)      Benchmark share for input  pc(good) in nest s for sector w
        theta_009            Benchmark share for output pw in nest t for sector w
;



*   Invoke the function preprocessor


$sysinclude gams-f

c0_002(sect,good) = qcomin(good,sect);                                 
c0_003(sect,fac) = qfacin(fac,sect);                                   
r0_005(sect) = qcom(sect);                                             
c0_001(sect) = +sum(good,c0_002(sect,good))+sum(fac,c0_003(sect,fac)); 
r0_004(sect) = +r0_005(sect);                                          
c0_007(good) = qhous(good);                                            
r0_009 = qw;                                                           
c0_006 = +sum(good,c0_007(good));                                      
r0_008 = +r0_009;                                                      
theta_002(sect,good) = c0_002(sect,good)/c0_001(sect); 
theta_003(sect,fac) = c0_003(sect,fac)/c0_001(sect);   
theta_005(sect) = r0_005(sect)/r0_004(sect);           
theta_007(good) = c0_007(good)/c0_006;                 
theta_009 = r0_009/r0_008;                             

*   Cost functions

p_002(sect,good) == pc(good);                                                                                    
p_003(sect,fac) == pf(fac);                                                                                      
p_005(sect) == pc(sect);                                                                                         
p_001(sect) == prod(good,p_002(sect,good)**theta_002(sect,good))*prod(fac,p_003(sect,fac)**theta_003(sect,fac)); 
p_004(sect) == theta_005(sect)*p_005(sect);                                                                      
p_007(good) == pc(good);                                                                                         
p_009 == pw;                                                                                                     
p_006 == prod(good,p_007(good)**theta_007(good));                                                                
p_008 == theta_009*p_009;                                                                                        

*   Quantity functions

q_002(sect,good) == qcomin(good,sect); 
q_003(sect,fac) == qfacin(fac,sect);   
q_005(sect) == qcom(sect);             
q_007(good) == qhous(good);            
q_009 == qw;                           

*   Compensated demand indices:

d_001(sect) ==  1;                                                    
d_002(sect,good) == d_001(sect)* (p_001(sect)/p_002(sect,good))**1.0; 
d_003(sect,fac) == d_001(sect)* (p_001(sect)/p_003(sect,fac))**1.0;   
d_006 ==  1;                                                          
d_007(good) == d_006* (p_006/p_007(good))**1.0;                       

*   Compensated supply indices:

s_004(sect) ==  1;                                        
s_005(sect) == s_004(sect)* (p_004(sect)/p_005(sect))**0; 
s_008 ==  1;                                              
s_009 == s_008* (p_008/p_009)**0;                         

*   Endowments:

e_010(fac) == endow(fac); 


POSITIVE VARIABLES
        xcom(sect) production
        w          welfare
        pc(sect)   price of commodity sect
        pf(fac)    price of factor fac
        pw         consumer price index
        y          total nominal household expenditure;


EQUATIONS
        prf_xcom(sect) "production"
        prf_w          "welfare"
        mkt_pc(sect)   "price of commodity sect"
        mkt_pf(fac)    "price of factor fac"
        mkt_pw         "consumer price index"
        inc_y          "total nominal household expenditure";



MODEL sj / prf_xcom.xcom,prf_w.w,mkt_pc.pc,mkt_pf.pf,mkt_pw.pw,inc_y.y/; 

*     Level value assignments
xcom.l(sect) = 1; 
w.l = 1;          
pc.l(sect) = 1;   
pf.l(fac) = 1;    
pw.l = 1;         

*     Zero profit conditions
prf_xcom(sect).. c0_001(sect)*p_001(sect) =G= r0_004(sect)*p_004(sect);
prf_w..          c0_006*p_006 =G= r0_008*p_008;

*     Market clearance conditions
mkt_pc(sect).. 
               s_005(sect)*xcom(sect)*q_005(sect)+sum((good,sect_)$(sameas(sect,good)),-d_002(sect,good)*xcom(sect_)*q_002(sect,good))+sum((good)$(sameas(sect,good)),-d_007(good)*w*q_007(good)) =e= 0;
mkt_pf(fac)..  
               +sum(sect,-d_003(sect,fac)*xcom(sect)*q_003(sect,fac)) + e_010(fac) =e= 0;
mkt_pw..       
               s_009*w*q_009-y/pw =e= 0;

*     Income definitions
inc_y.. 
        y =e=+sum((fac,pf(fac)*endow(fac));

*     Auxiliary constraints:
